//package com.htu.courseService.auth.strategy;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.jn.home.auth.entity.LoginUser;
//import com.jn.home.auth.request.LoginRequest;
//import com.jn.home.auth.response.LoginResult;
//import com.jn.home.auth.respository.LoginUserMapper;
//import com.jn.home.auth.respository.PermissionMapper;
//import com.jn.home.auth.respository.RoleMapper;
//import com.jn.home.common.exception.BaseException;
//import com.jn.home.common.utils.RedisCache;
//import lombok.RequiredArgsConstructor;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.stereotype.Component;
//
//import java.util.Objects;
//
//import static com.jn.home.common.enums.ResponseCodeEnum.CODE_NOT_EXIST;
//import static com.jn.home.common.enums.ResponseCodeEnum.USER_NOT_FOUND;
//
///**
// * Created By JNNarrator on 2024/9/7 16:43
// * email: jiangn09@chinatelecom.cn
// */
//@Component("mail")
//@RequiredArgsConstructor
//public class MailLoginStrategy implements LoginStrategy{
//	private final LoginUserMapper loginUserMapper;
//	private final RoleMapper roleMapper;
//	private final PermissionMapper permissionMapper;
//	private final RedisCache redisCache;
//
//	@Override
//	public LoginResult login(LoginRequest request) {
//		String email = request.getAccount();
//		String code = request.getPassword();
//		LoginUser loginUser = loginUserMapper.selectOne(new QueryWrapper<LoginUser>().eq("email", email));
//		if (Objects.isNull(loginUser)){
//			throw new BaseException(USER_NOT_FOUND);
//		}
//		String cacheCode = redisCache.getCacheObject("login:mail:code:" + loginUser.getId());
//		if (StringUtils.isEmpty(cacheCode)){
//			throw new BaseException(CODE_NOT_EXIST);
//		}
//		if (!StringUtils.equals(code,cacheCode)){
//			throw new BaseException(USER_NOT_FOUND);
//		}
//		return loginSuccess(loginUser, roleMapper, permissionMapper);
//	}
//}
